package com.imooc.diveinspringboot;

import com.imooc.diveinspringboot.mybatis.service.ChannelService;
import java.util.Arrays;
import javax.annotation.Resource;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;

/**
 * @author Chris
 */
@SpringBootApplication
@MapperScan(basePackages = {"com.imooc.diveinspringboot.mybatis.mapper"})
public class MybatisSpringBootApp implements CommandLineRunner {

    @Resource
    private ChannelService channelService;

    public static void main(String[] args) {
        SpringApplication.run(MybatisSpringBootApp.class, args);

        //disabled banner, don't want to see the spring logo
        // SpringApplication app = new SpringApplication(MybatisSpringBootApp.class);
        // app.setBannerMode(Banner.Mode.OFF);
        // app.setWebApplicationType(WebApplicationType.NONE);
        // app.run(args);
    }

    @Override
    public void run(String... args) {
        channelService.start();
    }

    @Bean
    CommandLineRunner commandLineRunner(ApplicationContext ctx) {
        return args -> Arrays.stream(ctx.getBeanDefinitionNames()).forEach(System.out::println);
    }
}

